package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.CrmCustomerSalary;
import com.linxiao.hrcrm.service.ICrmCustomerSalaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户薪资记录Controller
 *
 * @author zhoudong
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/hrcrm/salary")
public class CrmCustomerSalaryController extends BaseController {
    @Autowired
    private ICrmCustomerSalaryService crmCustomerSalaryService;

    /**
     * 查询客户薪资记录列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerSalary crmCustomerSalary) {
        startPage();
        List<CrmCustomerSalary> list = crmCustomerSalaryService.selectCrmCustomerSalaryList(crmCustomerSalary);
        return getDataTable(list);
    }

    /**
     * 获取某员工的薪资记录
     */
    @GetMapping("/findByUser")
    public TableDataInfo findByUser(CrmCustomerSalary crmCustomerSalary) {
        startPage();
        List<CrmCustomerSalary> list = crmCustomerSalaryService.findByUser(crmCustomerSalary);
        return getDataTable(list);
    }

    /**
     * 导出客户薪资记录列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:export')")
    @Log(title = "客户薪资记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerSalary crmCustomerSalary) {
        List<CrmCustomerSalary> list = crmCustomerSalaryService.selectCrmCustomerSalaryList(crmCustomerSalary);
        ExcelUtil<CrmCustomerSalary> util = new ExcelUtil<CrmCustomerSalary>(CrmCustomerSalary.class);
        util.exportExcel(response, list, "客户薪资记录数据");
    }

    /**
     * 获取客户薪资记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(crmCustomerSalaryService.selectCrmCustomerSalaryById(id));
    }

    /**
     * 新增客户薪资记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:add')")
    @Log(title = "客户薪资记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerSalary crmCustomerSalary) {
        return toAjax(crmCustomerSalaryService.insertCrmCustomerSalary(crmCustomerSalary));
    }

    /**
     * 修改客户薪资记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:edit')")
    @Log(title = "客户薪资记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerSalary crmCustomerSalary) {
        return toAjax(crmCustomerSalaryService.updateCrmCustomerSalary(crmCustomerSalary));
    }

    /**
     * 删除客户薪资记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:salary:remove')")
    @Log(title = "客户薪资记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSalaryService.deleteCrmCustomerSalaryByIds(ids));
    }

    /**
     * 签卡审批通过
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:audit')")
    @Log(title = "签卡审批通过", businessType = BusinessType.UPDATE)
    @PutMapping("/audits/{ids}")
    public AjaxResult audit(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSalaryService.audits(ids));
    }

    /**
     * 批量结算
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:settle')")
    @Log(title = "批量结算", businessType = BusinessType.UPDATE)
    @PutMapping("/settle/{ids}")
    public AjaxResult settle(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSalaryService.settle(ids));
    }

    /**
     * 批量发薪
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:grant')")
    @Log(title = "批量发薪", businessType = BusinessType.UPDATE)
    @PutMapping("/grant/{ids}")
    public AjaxResult grant(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSalaryService.grant(ids));
    }
}
